
package com.insigma.business.qrcode.common.converter;

import cn.hutool.core.collection.CollectionUtil;
import com.insigma.business.qrcode.job.entity.JobFairBO;
import com.insigma.business.qrcode.soldier.dto.*;
import com.insigma.business.qrcode.soldier.entity.CompanyDO;
import com.insigma.business.qrcode.soldier.entity.JobFairParticipateDO;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;


public class CompanyProviderConverter extends AbstractConverter<CompanyDTO, CompanyDO> {

    private final static CompanyProviderConverter companyConverter = new CompanyProviderConverter();

    private CompanyProviderConverter(){}


    public static CompanyBSearcher convertRequestSO2Searcher(final CompanySearchRequest request){
        final CompanyBSearcher companyBSearcher = new CompanyBSearcher(request.getPageNo(),
        request.getPageSize(),request.getSortKeyValueJoint());
        BeanUtils.copyProperties(request,companyBSearcher);
        return companyBSearcher;
    }


    public static CompanyDO convertRequestUO2DO(final CompanyUpdateRequest companyUpdateRequest) {
        final CompanyDO companyDO = new CompanyDO();
        BeanUtils.copyProperties(companyUpdateRequest,companyDO);

        return companyDO;
    }


    public static CompanyDO convertRequestIO2DO(final CompanyInsertRequest companyInsertRequest) {
        final CompanyDO companyDO = new CompanyDO();
        BeanUtils.copyProperties(companyInsertRequest,companyDO);
        return companyDO;
    }


    public static List<CompanyDTO> convertResponseDOList2DTOList(final List<CompanyDO> companyDOList){
        return companyConverter.convertGenericResponseDOList2DTOList(companyDOList);
    }

    public static CompanyDTO convertResponseDO2DTO(final CompanyDO companyDO){
        return companyConverter.convertGenericResponseDO2DTO(companyDO);
    }

    public static List<CompanyDTO> convertResponseBOList2DTOList(List<JobFairBO> jobFairBOS) {
        List<CompanyDTO> list = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(jobFairBOS)) {
            for (JobFairBO jobFairBO : jobFairBOS) {
                CompanyDTO dto = new CompanyDTO();
                BeanUtils.copyProperties(jobFairBO,dto);
                list.add(dto);
            }
        }
        return list;
    }

    public static CompanyDO convertJobFairParticipateDO2CompanyDO(JobFairParticipateDO jobFairParticipateDO) {
        CompanyDO companyDO = new CompanyDO();
        BeanUtils.copyProperties(jobFairParticipateDO,companyDO);
        companyDO.setName(jobFairParticipateDO.getOrgName());
        return companyDO;
    }


    @Override
    protected CompanyDTO doConvertResponseDO2DTO(CompanyDO companyDO) {
        final CompanyDTO companyDTO = new CompanyDTO();
        try {
            BeanUtils.copyProperties(companyDO, companyDTO);
        }catch(RuntimeException be){

            return null;
        }
        return companyDTO;
    }

}
